package com.mocha.common.kits;

import cn.hutool.core.date.DateUtil;

import java.sql.Timestamp;
import java.time.*;
import java.time.format.DateTimeFormatter;
import java.util.Date;

public class TimeTest {

    public static void main(String[] args) {
        LocalDateTime dateTime = LocalDateTime.now();
        System.out.println(dateTime.getHour());
        System.out.println(dateTime.getYear());
        System.out.println(dateTime.getMonth().getValue());
        System.out.println(dateTime.getDayOfMonth());

        LocalDateTime after = dateTime.plusHours(3);
        System.out.println(after.getHour());


        ltd();


        System.out.println(DateUtil.beginOfMonth(new Date()).toMsStr());

        System.out.println(DateUtil.endOfMonth(new Date()).toMsStr());



    }

    public static  void ltd(){
        LocalDateTime localDateTime = LocalDateTime.parse("2019-11-15T13:15:30");

        Instant instant = localDateTime.atZone(ZoneId.systemDefault()).toInstant();
        Date date = Date.from(instant);
        System.out.println(date);

        instant = localDateTime.toInstant(ZoneOffset.UTC);
        date = Date.from(instant);
        System.out.println(date);

        instant = Timestamp.valueOf(localDateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))).toInstant();
        date = Date.from(instant);
        System.out.println(date);

        Timestamp timestamp = Timestamp.valueOf(localDateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
        date = new Date(timestamp.getTime());
        System.out.println(date);

    }


    public static void doTime(){
        String start ="10:12";
        String end = "23:15";
        int cy = 90;
        int[] startArray = StringKits.splitToInt(start, ":");
        int[] endArray = StringKits.splitToInt(end, ":");
        LocalDateTime dateTime = LocalDateTime.now();
//        LocalDateTime targetStart = LocalDateTime.of(LocalDate.now(), LocalTime.of(startArray[0], startArray[1]));
        LocalDateTime targetEnd = LocalDateTime.of(LocalDate.now(), LocalTime.of(endArray[0], endArray[1]));

        LocalTime s = LocalTime.of(startArray[0], startArray[1]);

      /*  System.out.println(targetStart.getHour());
        System.out.println(targetStart.getYear());
        System.out.println(targetStart.getMonth().getValue());
        System.out.println(targetStart.getDayOfMonth());

        System.out.println("---------------------------");

        System.out.println(targetEnd.getHour());
        System.out.println(targetEnd.getYear());
        System.out.println(targetEnd.getMonth().getValue());
        System.out.println(targetEnd.getDayOfMonth());

        System.out.println("---------------2222------------");

        System.out.println(targetStart.compareTo(targetEnd));*/


//
//        for ( LocalDateTime targetStart = LocalDateTime.of(LocalDate.now(), LocalTime.of(startArray[0], startArray[1])); targetStart.compareTo(targetEnd) < 1; targetStart = targetStart.plusMinutes(cy)){
//
//            if (targetStart.compareTo(dateTime) >-1){
//                System.out.println(targetStart.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")) + " "+ targetStart.plusMinutes(cy).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
//            }
//
//        }


    }
}
